//
//  MBScanPreviewViewModel.m
//  MemberBusiness-ios
//
//  Created by 掌心 on 2018/6/1.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBScanPreviewViewModel.h"

@implementation MBScanPreviewViewModel

-(void)setPhotoImage:(UIImage *)photoImage{
    _photoImage = photoImage;

    // 创建一个CIImage对象
    CIImage *ciImage = [[CIImage alloc] initWithCGImage:photoImage.CGImage options:nil];
    CIContext *context = [CIContext contextWithOptions:@{kCIContextUseSoftwareRenderer : @(YES)}]; // 软件渲染
    CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:@{CIDetectorAccuracy : CIDetectorAccuracyHigh}];// 二维码识别
    // 注意这里的CIDetectorTypeQRCode
    NSArray *features = [detector featuresInImage:ciImage];
    NSLog(@"features = %@",features); // 识别后的结果集
    for (CIQRCodeFeature *feature in features) {
        NSLog(@"msg = %@",feature.messageString); // 打印二维码中的信息
    }
}

@end
